package cn.com.ejiakanghu.core.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wj
 * @date 2021/10/19 13:37
 */
@Configuration
public class DirectExchangeRabbitMQConfig {


    //交换机
    public static final String DIRECT_EXCANGE_NAME = "wechatNoticeExchange";


    //Routing Key
    public static final String TO_WECHAT_NOTICE = "toWechatNotice";

    public static final String TO_LITEMALL = "toLitemall";

    public static final String TO_LITEMALL_NOTICE = "toLitemallNotice";


    public static final String ROUTING_KEY_OLDER_DEPLOY = "older_msg";


    //Queue
    public static final String FROM_LITEMALL_TO_NOTICE = "fromLitemallToNotice";

    public static final String FROM_NOTICE_TO_LITEMALL = "fromNoticeToLitemall";

    public static final String FROM_LOGISTICS_TO_NOTICE = "fromLogisticsToNotice";

    public static final String FROM_ROUTING_TO_NOTICE = "fromRoutingToNotice";

    //微信退款队列 Routing Key
    public static final String QUEUE_WX_REFUND = "wx_refund_queue";

    //微信提现队列
    public static final String USER_WX_WITHDRAWAL_QUEUE = "user_Wx_Withdrawal_Queue";

    //将队列和交换机绑定
    public static final String USER_WX_DIRECTROUTING = "directRouting";

    // 声明直连交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECT_EXCANGE_NAME);
    }

    // 声明消息队列
    @Bean
    public Queue fromLitemallToNotice() {
        return new Queue(FROM_LITEMALL_TO_NOTICE);
    }

    @Bean
    public Queue fromNoticeToLitemall() {
        return new Queue(FROM_NOTICE_TO_LITEMALL);
    }

    @Bean
    public Queue fromLogisticsToNotice() {
        return new Queue(FROM_LOGISTICS_TO_NOTICE);
    }

    @Bean
    public Queue fromRoutingToNotice() {
        return new Queue(FROM_ROUTING_TO_NOTICE);
    }


    // 向直连交换机上绑定队列
    @Bean
    Binding bindingQueue4ExchangeNotice(Queue fromLitemallToNotice, DirectExchange directExchange) {
        return BindingBuilder.bind( fromLitemallToNotice )
                .to( directExchange )
                .with( TO_WECHAT_NOTICE );
    }


    @Bean
    Binding bindingQueue4ExchangeLitemall(Queue fromNoticeToLitemall, DirectExchange directExchange) {
        return BindingBuilder.bind( fromNoticeToLitemall )
                .to( directExchange )
                .with( TO_LITEMALL );
    }


    @Bean
    Binding bindingQueue4LogisticToNotice(Queue fromLogisticsToNotice, DirectExchange directExchange) {
        return BindingBuilder.bind( fromLogisticsToNotice )
                .to( directExchange )
                .with( TO_LITEMALL_NOTICE );
    }

    @Bean
    Binding bindingQueue4RoutingToNotice(Queue fromRoutingToNotice, DirectExchange directExchange) {
        return BindingBuilder.bind( fromRoutingToNotice )
                .to( directExchange )
                .with( ROUTING_KEY_OLDER_DEPLOY );
    }

}
